package com.yanshaohui.controller;

import com.yanshaohui.bean.Person;
import com.yanshaohui.feign.ProviderReactive;
import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * Created by TS-Ysh on 2018-05-16.
 */
@RestController
@RequestMapping("feign/flux")
public class FeignReactiveTestController {

    @Autowired
    private ProviderReactive providerReactive;

    @GetMapping("/person/{id}")
    public Mono<Person> getOnePerson(@PathVariable("id") Long id){
        return Mono.just(providerReactive.getOnePerson(id));
    }

    /**
     * springmvcweb方式，和上面React方式比较一下性能
     * @param id
     * @return
     */
    @GetMapping("/person2/{id}")
    public Person getOnePerson2(@PathVariable("id") Long id){
        return providerReactive.getOnePerson2(id);
    }

    @GetMapping("/persons")
    public Flux<Person> getAllPerson(){
        return Flux.fromIterable(providerReactive.getAllPerson());
    }


    @GetMapping("/test1")
    public Mono<ServerResponse> test1(){
        return Mono.just(providerReactive.test1());
    }

    @GetMapping("/people")
    public Mono<String> test2(){
        return Mono.just(providerReactive.test2());
    }
}
